package com.guigu.www.service.imp;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.www.mapper.RolesMapper;
import com.guigu.www.mapper.UsersMapper;
import com.guigu.www.pojo.Roles;
import com.guigu.www.service.RolesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RolesServiceImpl extends ServiceImpl<RolesMapper, Roles> implements RolesService {
    @Autowired
    RolesMapper mapper;
    //获取账号map
    @Autowired
    UsersMapper usersMapper;
    @Override
    public List<Roles> querybyroleid(int userid) {
        List<Roles> roles=mapper.queryall();
        List<Integer> list=mapper.querybyuserid(userid);
        for(Roles roles1: roles){
            if(list.contains(roles1.getId())){
                roles1.setCheck(true);
            }
        }
        return roles;
    }

    @Override
    public List<Integer> querryByusersRoleByusername(String username) {
        //查询当前角色的id
        int userid=usersMapper.queryByUserRoleId(username);
        //查询所有角色id
        return mapper.querryByusersRoleByusername(userid);
    }
}
